package com.dyzx.hbb.modules.attendance.controller;

import com.dyzx.hbb.common.base.Result;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.common.controller.BaseValidController;
import com.dyzx.hbb.modules.attendance.entity.AttendanceDevice;
import com.dyzx.hbb.modules.attendance.entity.AttendanceLeaveCategory;
import com.dyzx.hbb.modules.attendance.query.AttendanceLeaveCategoryQuery;
import com.dyzx.hbb.modules.attendance.service.AttendanceLeaveCategoryService;
import com.dyzx.hbb.modules.attendance.vo.AttendanceLeaveCategoryUpdateUVO;
import com.dyzx.hbb.modules.attendance.vo.AttendanceLeaveCategoryVO;
import com.dyzx.hbb.security.context.SecurityContextHolder;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
///attendance/leave/category/mini_list
@RestController
@RequestMapping("/attendance/leave/category")
public class AttendanceLeaveCategoryController extends BaseValidController<AttendanceLeaveCategoryService, AttendanceLeaveCategory, AttendanceLeaveCategoryQuery, AttendanceLeaveCategoryVO, AttendanceLeaveCategoryUpdateUVO> {


   @Autowired
   private AttendanceLeaveCategoryService service;

    @Override
    protected AttendanceLeaveCategory addValid(AttendanceLeaveCategoryVO entity) {
        return null;
    }

    @Override
    protected AttendanceLeaveCategory editValid(AttendanceLeaveCategoryUpdateUVO entity) {
        return null;
    }

    @Override
    protected AttendanceLeaveCategoryService getBaseService() {
        return service;
    }

    @Override
    protected MyLambdaQueryWrapper<AttendanceLeaveCategory> queryWrapper(AttendanceLeaveCategoryQuery query) {
        return null;
    }

    @Override
    protected MyLambdaQueryWrapper<AttendanceLeaveCategory> queryInfoWrapper() {
        return null;
    }

    @GetMapping("/mini_list")
    @Operation(summary = "获取考勤配置精简列表", description = "获取所有考勤配置的精简信息，仅包含ID和名称，用于下拉选择")
    public Result<List<Map<String, Object>>> miniList(@RequestParam(required = false, defaultValue = "0") Integer type) {
        Long organId = SecurityContextHolder.getOrganId();
        MyLambdaQueryWrapper<AttendanceLeaveCategory> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(AttendanceLeaveCategory::getId).as("value");
        queryWrapper.select(AttendanceLeaveCategory::getName).as("label");
        queryWrapper.orderByDesc(AttendanceLeaveCategory::getId);
        if(type != null && type > 0) {
            queryWrapper.eq(AttendanceLeaveCategory::getType, type);
        }
        queryWrapper.eq(AttendanceLeaveCategory::getOrganId, organId).or().isNull(AttendanceLeaveCategory::getOrganId);
        List<Map<String, Object>> maps = service.listMaps(queryWrapper);
        if (maps.isEmpty()) {
            return Result.error(404, "暂无数据");
        }
        return Result.ok(maps);
    }
}
